/*
 * This file Copyright (c) 2015. Walle.
 * (http://www.wallellen.com). All rights reserved.
 *
 *
 * This file is dual-licensed under both the
 * Walle Agreement (WA) and the GNU General Public License.
 * You may elect to use one or the other of these licenses.
 *
 * This file is distributed in the hope that it will be
 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
 * Redistribution, except as permitted by whichever of the GPL
 * or WA you select, is prohibited.
 *
 * 1. For the GPL license (GPL), you can redistribute and/or
 * modify this file under the terms of the GNU General
 * Public License, Version 3, as published by the Free Software
 * Foundation.  You should have received a copy of the GNU
 * General Public License, Version 3 along with this program;
 * if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * 2. For the Walle Agreement (WA), this file
 * and the accompanying materials are made available under the
 * terms of the WA which accompanies this distribution, and
 * is available at http://www.wallellen.com/agreement.html
 *
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 */

package com.wallellen.knowledge.doc.server;

import com.wallellen.core.auth.domain.LoginUser;
import com.wallellen.knowledge.doc.domain.Docfile;

import java.io.File;
import java.io.InputStream;
import java.util.List;

public interface FileManagerInter {
    /**
     * 附件类型
     *
     * @author <a href="mailto:wallellen@hotmail.com">WALLE</a>
     */
    public enum FILE_TYPE {
        HTML_INNER_IMG("1"), RESOURCE_FILE("2"), RESOURCE_ZIP("3"), OHTER("0"), WEB_FILE("4");
        private String value;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        FILE_TYPE(String value) {
            this.value = value;
        }
    }

    /**
     * 保存一个附件到系统中
     *
     * @param file
     * @param type
     * @param title
     * @return 附件ID
     */
    public String saveFile(File file, FILE_TYPE type, String title, LoginUser user);

    /**
     * 保存一个附件到系统中
     *
     * @param inStream 文件流
     * @param filename 文件名称
     * @param title    文件title
     * @param type     文件类型
     * @param user     当前用户
     * @return
     */
    public String saveFile(InputStream inStream, String filename, String title, FILE_TYPE type, LoginUser user);

    /**
     * 由文件id获得下载链接
     *
     * @param fileid 文件id
     * @return
     */
    public String getFileURL(String fileid);

    /**
     * 由文件id获得文件对象
     *
     * @param fileid
     * @return
     */
    public Docfile getFile(String fileid);

    /**
     * 获得一个默认图片
     *
     * @param file
     * @return
     */
    public File getNoneImg();

    /**
     * 将文件状态改为提交状态，否则为临时状态
     *
     * @param fileId
     */
    public void submitFile(String fileId);

    /**
     * 将文件设置为临时状态
     *
     * @param fileId
     */
    public void cancelFile(String fileId);

    /**
     * 删除一个文件
     *
     * @param fileId
     */
    public void delFile(String fileId, LoginUser user);

    /**
     * 创建并使用一个新的文件（并附带一个已经存在的File对象）
     *
     * @param exname  扩展名
     * @param content 备注
     * @param user
     * @return
     */
    public Docfile openFile(String exname, String content, LoginUser user);

    /**
     * 为文档添加一个附件
     *
     * @param docid
     * @param fileId
     * @param user
     */
    public void addFileForDoc(String docid, String fileId, LoginUser user);

    /**
     * 为文档删除一个附件
     *
     * @param docid
     * @param fileId
     * @param user
     */
    public void delFileForDoc(String docid, String fileId, LoginUser user);

    /**
     * 删除一个文档的所有附件
     *
     * @param docid
     * @param fileId
     * @param user
     */
    public void delFileForDoc(String docid, LoginUser user);

    /**
     * 获得文档的所有附件
     *
     * @param docid
     */
    public List<Docfile> getAllFileForDoc(String docid);

    /**
     * 获得文档的某类型的所有附件
     *
     * @param docid
     * @param exname 扩展名如.doc
     * @return
     */
    public List<Docfile> getAllTypeFileForDoc(String docid, String exname);

    /**
     * 文档是否包含一个附件
     *
     * @param id
     * @param zipfileId
     * @return
     */
    public boolean containFileByDoc(String docid, String fileId);

    /**
     * 删除一个文档的所有某类型附件
     *
     * @param docid     文档id
     * @param exname    扩展名如.doc
     * @param LoginUser
     */
    public void delAllFileForDoc(String docid, String exname, LoginUser LoginUser);
}
